/*
**game_event.c for game_event.c in /home/vriely/Dropbox/work/Unix/Zappy_rendu/serv-src
**
**Made by Samuel Vrielynck
**Login   <vriely_s@epitech.net>
**
**Started on  Tue Jun 19 11:01:43 2012 Samuel Vrielynck
** Last update Fri Jul 20 09:32:43 2012 guillaume renard
*/

#include	<stdlib.h>
#include	<string.h>

#include	"server.h"

char		*expulse(t_client *client, t_game *game)
{
  client->gamer->action = 7 * MILLI / game->time;
  game->event->add_back(game->event,
      new_event(EXPULSE, 7 * MILLI / game->time,
	new_expulse(client)));
  return (strdup("ok\n"));
}

char		*pond(t_client *client, t_game *game)
{
  client->gamer->action = 42 * MILLI / game->time;
  game->event->add_back(game->event,
      new_event(FORK, 42 * MILLI / game->time,
	new_fork(client->gamer->coord, client)));
  serv_monitor("pfk", client, game, game->graphic);
  return (strdup("ok\n"));
}

char		*broadcast(t_client *client, t_game *game)
{
  char		*bkp;
  char		*str;

  str = (char *)client->gamer->task->head->content;
  bkp = strdup(str + 9);
  if (strtok(str, " ") != NULL && strtok(NULL, " "))
  {
    printf("New broadcast with msg : %s\n", bkp);
    game->event->add_back(game->event,
	new_event(BROADCAST, 7 * MILLI / game->time,
	  new_broadcast(client->gamer->coord, bkp, client)));
    if (game->graphic != NULL)
    {
      game->graphic->send->concat(game->graphic->send, "pbc ");
      game->graphic->send->concat_value(game->graphic->send, client->sock);
      game->graphic->send->concat(game->graphic->send, " ");
      game->graphic->send->concat(game->graphic->send, bkp + 1);
      game->graphic->send->concat(game->graphic->send, "\n");
    }
  }
  else
    free(bkp);
  return (strdup("ok\n"));
}
